<template>
  <div class="city">
    <div class="hot">
      <span>热门城市</span>
      <ul>
        <li v-for="item in hotCity" :key="item.pre" @click="chooseCity(item)">
          {{ item.name }}
        </li>
      </ul>
    </div>
    <div class="citylist" v-for="item in cityList" :key="item.prefix">
      <div>
        {{ item.prefix }}
      </div>
      <ul>
        <li
          v-for="item in item.cities"
          :key="item.cities"
          @click="chooseCity(item)"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import { onMounted, computed } from "@vue/runtime-core";
import { useStore } from "vuex";
export default {
  setup() {
    // let list = ref([]);
    const store = useStore();
    const hotCity = computed(() => {
      // console.log(store.state.indeximg);
      return store.state.hotCity;
    });
    const cityList = computed(() => {
      return store.state.cityList;
    });
    onMounted(() => {
      // console.log(store.state.city.hotCity);
      store.dispatch("getCityList");
      // this.changeCityList();
      // this.changehotCity();
    });
    return { hotCity, cityList };
  },
  methods: {
    // getCityList() {
    //     this.$store.dispatch("getCityList");
    // },
    // ...mapActions(["getCityList"]),
    // getCityList(){
    //     return
    // }
    // getCityList() {
    // fetch("http://www.pudge.wang:3080/api/area/list")
    //     .then((response) => response.json())
    //     .then((res) => {
    //         console.log(res.result);
    //         this.cityList = res.result.slice(1);
    //         console.log(this.cityList);
    //         this.hotCity = res.result.slice(0, 1)[0].cities;
    //     });
    // },
    chooseCity(city) {
      let s = { name: city.name, id: city.cityId };
      this.$router.push("/home");
      this.$store.commit("changeCity", s);
    },
  },
};
</script>

<style lang="less" scoped>
.city {
  background-color: #ebebeb;
  .hot {
    padding-bottom: 15px;
    background-color: #f5f5f5;
    span {
      display: block;
      padding-left: 15px;
      line-height: 30px;
      font-size: 14px;
      color: #333;
      width: 100%;
      background-color: #ebebeb;
    }
    ul {
      width: 100%;
      display: flex;
      flex-wrap: wrap;
      font-size: 14px;
      background-color: #f5f5f5;
      justify-content: space-around;
      align-content: space-between;
      height: 192px;
      li {
        width: 29%;
        height: 33px;
        line-height: 33px;
        background-color: #fff;
        text-align: center;
        margin-top: 15px;
        border: 1px solid #e6e6e6;
        border-radius: 3px;
      }
    }
  }
  .citylist {
    font-size: 14px;
    li {
      line-height: 44px;
      padding-left: 15px;
      border-bottom: 1px solid #c8c7cc;
      background-color: #f5f5f5;
    }
    div {
      width: 100%;
      background-color: #ebebeb;
      height: 30px;
      font-size: 18px;
      line-height: 30px;
      padding-left: 15px;
    }
  }
}
</style>
